//
//  SettingTableViewCell.m
//  EZ Tracker
//
//  Created by FENGYL on 2017/3/16.
//  Copyright © 2017年 FENGYL. All rights reserved.
//

#import "SettingTableViewCell.h"
#import "InfoSettingViewController.h"
#import "SettingViewController.h"
#import "UserModel.h"

@interface SettingTableViewCell()

@property (strong, nonatomic) UserModel *userModel;

@property (weak, nonatomic) IBOutlet UIImageView *cellIcon;
@property (weak, nonatomic) IBOutlet UILabel *deviceName;

@end

@implementation SettingTableViewCell

-(UserModel *)userModel{
    
    if (!_userModel) {
        
        _userModel = [[UserModel alloc]init];
        
    }
    return _userModel;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark 设置信息
-(void)setUpCellForDeviceName:(NSString *)deviceName{
    
    [self.deviceName setText:deviceName];
    
}

#pragma mark 设置头像
-(void)setUpIconForImage:(UIImage *)image{
    
    if (!image) {
        
        image = [UIImage imageNamed:@"ic_tracker_useractivity_yuan_2"];
        
    }
    
    
    [self.cellIcon setImage:image];
    
}

#pragma mark 点击编辑
- (IBAction)editDevice:(id)sender {
    
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"SettingViewController" bundle:[NSBundle mainBundle]];
    
    InfoSettingViewController *infoSettingViewController = [storyboard instantiateViewControllerWithIdentifier:@"InfoSettingViewController"];
    
    
    for (UIView *next = [self superview]; next; next = next.superview) {
        UIResponder* nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[SettingViewController class]]) {
            
            SettingViewController *settingViewController = (SettingViewController *)nextResponder;
            
            infoSettingViewController.deviceName = self.deviceName.text;
            
            infoSettingViewController.serialNumber = self.serialNumber;
            
            [settingViewController.navigationController showViewController:infoSettingViewController sender:nil];
            
            break;
        }
    }
        
    


    
}


@end
